package ssm.com.jy.controller;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import ssm.com.jy.Message;
import ssm.com.jy.entity.CoursePartBean;
import ssm.com.jy.entity.CoursesBean;
import ssm.com.jy.entity.TestBean;
import ssm.com.jy.service.CourseService;
import ssm.com.jy.service.TestService;

@Controller
public class MainController {
    private static Logger log = Logger.getLogger(MainController.class.getName());

    @Resource
    private TestService mTestService;
    @Resource
    private CourseService mCourseService;

    @RequestMapping("/test")
    @ResponseBody
    public Message TestMessage() {
        List<TestBean> list = mTestService.selectAll();
        Message msg = new Message();
        msg.setCode(1);
        msg.setMsg("请求成功！");
        msg.setData(list);
        return msg;
    }

    @RequestMapping("/testid")
    @ResponseBody
    public Message TestIdMessage() {
        //根据主键id查询数据
        TestBean testBean = mTestService.selectByPrimaryKey(1);
        Message msg = new Message();
        msg.setCode(1);
        msg.setMsg("请求成功！");
        msg.setData(testBean);
        return msg;
    }

    @RequestMapping("/test0")
    @ResponseBody
    public Message Test0Message() {
        Message msg = new Message();
        msg.setCode(1);
        msg.setMsg("请求成功！");
        msg.setData(new HashMap<String,String>());   //花括弧
//        msg.setData(new ArrayList<>());     //中括弧
//        msg.setData(new TestBean());     //字段为null
        return msg;
    }

    @RequestMapping("/course")
    @ResponseBody
    public Message CourseMessage() {
        List<CoursesBean> list = mCourseService.selectAll();
        Message msg = new Message();
        msg.setCode(1);
        msg.setMsg("请求成功！");
        msg.setData(list);
        return msg;
    }

    @RequestMapping("/courseType")
    @ResponseBody
    public Message CourseTypeMessage() {
        List<CoursePartBean> list = mCourseService.queryByType();
        Message msg = new Message();
        msg.setCode(1);
        msg.setMsg("请求成功！");
        msg.setData(list);
        return msg;
    }
}
